import 'package:get_storage/get_storage.dart';

class SpInstance {
  String TAG = "SpInstance";

  static final _instance = SpInstance._();

  factory SpInstance.getInstance() => _instance;

  SpInstance._();

  void init() async {
    await GetStorage.init();
  }

  Future<void> setString(String k, String v) {
    final box = GetStorage();
    return box.write(k, v);
  }

  String getString(String k) {
    final box = GetStorage();
    var result = box.read<String>(k);
    if (result == null) {
      return '';
    }
    return result;
  }

  Future<void> setInt(String k, int v) {
    final box = GetStorage();
    return box.write(k, v);
  }

  int getInt(String k, {int? defaultV}) {
    final box = GetStorage();
    var result = box.read<int>(k);
    if (result == null) {
      return defaultV ?? 0;
    }
    return result;
  }

  Future<void> remove(String k) {
    final box = GetStorage();
    return box.remove(k);
  }
}
